using UnityEngine;
using System.Collections;

public class PopUp : MonoBehaviour
{
	private bool isMeshActived;
	
	public Vector3[] positionsToPopUp;
	public int timeBlinking;
	
	void Start ()
	{
		isMeshActived = true;
		GameObject[] go = GameObject.FindGameObjectsWithTag("PopUp");
		
		//Se já existir outro texto, não chamar a coroutina.
		if (go.Length > 1)
		{
			int lenght = go.Length;
			
			for (int i = 0; i < lenght - 1; i++)
				Destroy(go[i]);
		}
		
		StartCoroutine(Blink());
	}
	
	IEnumerator Blink ()
	{
		short count = 0;
		
		while (count < timeBlinking) {
			
			count += 1;
			isMeshActived = !isMeshActived;
				
			GetComponent<MeshRenderer> ().enabled = isMeshActived;
				
			yield return new WaitForSeconds (.5f);
		}
		
		//Certificar que o texto ficará falso.
		GetComponent<MeshRenderer>().enabled = false;
	}
	
	public string TextToPopUp { set { GetComponent<TextMesh>().text = value; GetComponent<MeshRenderer>().enabled = false; } }
}